﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameLogic.Objects
{
    class PlayerTank : Tank
    {

        public override void Move(Map map)
        {
            switch (CurrentDirection)
            {
                case Direction.NORTH:
                    TryMoveNorth(map);
                    break;
                case Direction.EAST:
                    TryMoveEast(map);
                    break;
                case Direction.SOUTH:
                    TryMoveSouth(map);
                    break;
                case Direction.WEST:
                    TryMoveWest(map);
                    break;
            }
        }

        public PlayerTank()
        {
            CurrentDirection = Direction.EAST;
            Position = new Rectangle(30, 30, Constants.TANK_WIDTH, Constants.TANK_HEIGHT);
            HitPoints = Constants.HITS_FOR_PLAYER;
        }

        public override Image GetCurrentImage()
        {
            switch (CurrentDirection)
            {
                case Direction.NORTH:
                    return PictureManager.GetImage(ImageKind.PLAYER_NORTH);
                case Direction.EAST:
                    return PictureManager.GetImage(ImageKind.PLAYER_EAST);
                case Direction.SOUTH:
                    return PictureManager.GetImage(ImageKind.PLAYER_SOUTH);
                case Direction.WEST:
                default:
                    return PictureManager.GetImage(ImageKind.PLAYER_WEST);
            }
        }

        public override void Shot()
        {
            Ready = !Ready;
            if (Ready)
            {
                var position = GetBulletRectangle();
                Bullet bullet = new Bullet(this)
                {
                    CurrentDirection = this.CurrentDirection,
                    Position = position,
                };

                BulletCreationEventArgs args = new BulletCreationEventArgs()
                {
                    Bullet = bullet,
                    IsPlayerBullet = true,
                };
                if (OnShot != null)
                {
                    OnShot(this, args);
                }
            }
        }

        public override event EventHandler<BulletCreationEventArgs> OnShot;

       /* public void Move(Map map, Direction preferredDirection)
        {
            bool moved = false;
            Ready = !Ready;
            switch (preferredDirection)
            {
                case Direction.NORTH:
                    moved = TryMoveNorth(map);
                    break;
                case Direction.EAST:
                    moved = TryMoveEast(map);
                    break;
                case Direction.SOUTH:
                    moved = TryMoveSouth(map);
                    break;
                case Direction.WEST:
                    moved = TryMoveWest(map);
                    break;
            }
            if (moved)
            {
                CurrentDirection = preferredDirection;
            }
        }*/
    }
}
